<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
class ps_ukcreditcard
{
	var $classname = "ps_ukcreditcard";
	var $payment_code = "UKCC";
	var $version = "1.1.2 Build 2";
	
	function show_configuration()
	{
		global $VM_LANG;
		
        /** Read current Configuration ***/
        require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
        //TODO: Need to switch the text to use $VM_LANG variable(s)
        ?>
        	<h3>UK Credit Card Payment Module</h3>
        	Version: <?php echo $this->version; ?>
        	<br />
			<table>
        	<tr>
				<td width="100">
					<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_MODE'); ?></strong>
				</td>
				<td width="75">
					<select name="UKCC_MODE" class="inputbox" >
						<option <?php if (@UKCC_MODE == 'live') echo "selected=\"selected\""; ?> value="live"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_LIVE') ?></option>
						<option <?php if (@UKCC_MODE == 'test') echo "selected=\"selected\""; ?> value="test"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_TEST') ?></option>
					</select>
				</td>
				<td>
					<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_MODE_EXPLAIN'); ?>
				</td>
			</tr>
   			<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_DEBUG'); ?></strong>
					</td>
					<td>
						<select name="UKCC_DEBUG" class="inputbox" >
                			<option <?php if (@UKCC_DEBUG == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_DEBUG != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_DEBUG_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_STARTDATE'); ?></strong>
					</td>
					<td>
						<select name="UKCC_STARTDATE" class="inputbox" >
                			<option <?php if (@UKCC_STARTDATE == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_STARTDATE != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_STARTDATE_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_ENDDATE'); ?></strong>
					</td>
					<td>
						<select name="UKCC_ENDDATE" class="inputbox" >
                			<option <?php if (@UKCC_ENDDATE == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_ENDDATE != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_ENDDATE_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_CCV'); ?></strong>
					</td>
					<td>
						<select name="UKCC_CCV" class="inputbox" >
                			<option <?php if (@UKCC_CCV == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_CCV != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_CCV_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_ISSUE'); ?></strong>
					</td>
					<td>
						<select name="UKCC_ISSUE" class="inputbox" >
                			<option <?php if (@UKCC_ISSUE == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_ISSUE != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_ISSUE_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_EMAIL_STARTDATE'); ?></strong>
					</td>
					<td>
						<select name="UKCC_EMAIL_STARTDATE" class="inputbox" >
                			<option <?php if (@UKCC_EMAIL_STARTDATE == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_EMAIL_STARTDATE != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_EMAIL_STARTDATE_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_EMAIL_ENDDATE'); ?></strong>
					</td>
					<td>
						<select name="UKCC_EMAIL_ENDDATE" class="inputbox" >
                			<option <?php if (@UKCC_EMAIL_ENDDATE == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_EMAIL_ENDDATE != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_EMAIL_ENDDATE_EXPLAIN'); ?>
					</td>
				</tr>
				<tr>
					<td>
						<strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_EMAIL_CCV'); ?></strong>
					</td>
					<td>
						<select name="UKCC_EMAIL_CCV" class="inputbox" >
                			<option <?php if (@UKCC_EMAIL_CCV == 'yes') echo "selected=\"selected\""; ?> value="yes"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES'); ?></option>
               				<option <?php if (@UKCC_EMAIL_CCV != 'yes') echo "selected=\"selected\""; ?> value="no"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO'); ?></option>
               			</select>
					</td>
					<td>
						<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_EMAIL_CCV_EXPLAIN'); ?>
					</td>
				</tr>
			</table>
 		<?php
	}
	    
	function has_configuration() 
	{
      // return false if there's no configuration
      return true;
	}
   

	/**
	* Returns the "is_writeable" status of the configuration file
	* @param void
	* @returns boolean True when the configuration file is writeable, false when not
	*/
	function configfile_writeable()
	{
		return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" );
	}
   
	/**
	* Returns the "is_readable" status of the configuration file
	* @param void
	* @returns boolean True when the configuration file is writeable, false when not
	*/
	function configfile_readable() 
	{
		return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
	}
	
	/**
	* Writes the configuration file for this payment method
	* @param array An array of objects
	* @returns boolean True when writing was successful
	*/
	function write_configuration( &$d ) 
	{
		require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
		if (! isset($d['UKCC_MODE'])) $d['UKCC_MODE'] = @UKCC_MODE;
		if (! isset($d['UKCC_DEBUG'])) $d['UKCC_DEBUG'] = @UKCC_DEBUG;
		if (! isset($d['UKCC_STARTDATE'])) $d['UKCC_STARTDATE'] = @UKCC_STARTDATE;
		if (! isset($d['UKCC_ENDDATE'])) $d['UKCC_ENDDATE'] = @UKCC_ENDDATE;
		if (! isset($d['UKCC_CCV'])) $d['UKCC_CCV'] = @UKCC_CCV;
		if (! isset($d['UKCC_ISSUE'])) $d['UKCC_ISSUE'] = @UKCC_ISSUE;
		if (! isset($d['UKCC_EMAIL_STARTDATE'])) $d['UKCC_EMAIL_STARTDATE'] = @UKCC_EMAIL_STARTDATE;
		if (! isset($d['UKCC_EMAIL_ENDDATE'])) $d['UKCC_EMAIL_ENDDATE'] = @UKCC_EMAIL_ENDDATE;
		if (! isset($d['UKCC_EMAIL_CCV'])) $d['UKCC_EMAIL_CCV'] = @UKCC_EMAIL_CCV;
		
		$my_config_array = array(
      						'UKCC_MODE' => $d['UKCC_MODE'],
      						'UKCC_DEBUG' => $d['UKCC_DEBUG'],
      						'UKCC_STARTDATE' => $d['UKCC_STARTDATE'],
      						'UKCC_ENDDATE' => $d['UKCC_ENDDATE'],
      						'UKCC_CCV' => $d['UKCC_CCV'],
							'UKCC_ISSUE' => $d['UKCC_ISSUE'],
							'UKCC_EMAIL_STARTDATE' => $d['UKCC_EMAIL_STARTDATE'],
							'UKCC_EMAIL_ENDDATE' => $d['UKCC_EMAIL_ENDDATE'],
							'UKCC_EMAIL_CCV' => $d['UKCC_EMAIL_CCV']
                            );
		$config = "<?php\n";
		$config .= "if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );; \n\n";
		foreach( $my_config_array as $key => $value )
		{
			$config .= "define ('$key', '$value');\n";
		}
		$config .= "?>";
  
		if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) 
		{
			fputs($fp, $config, strlen($config));
			fclose ($fp);
			return true;
		}
		else
		{
        	return false;
		}
   }
   
	function process_payment($order_number, $order_total, &$d)
	{
        return true;
    }
	
	
}
?>